php[architect] - February 2016 by php

php[architect] - February 2016 by php

Author:php[architect] & php[architect]
Language: eng
Format: epub
Publisher: php[architect]
Published: 2016-02-03T16:00:00+00:00


The Symfony Event Dispatcher

The Symfony Event Dispatcher implements the Mediator pattern, providing the means to decouple producers and consumers.

In Symfony, the consumers are referred to as listeners. Listeners are callables 3. They can be objects or functions.

The component at its core defines two interfaces, the EventDispatcherInterface and the EventSubscriberInterface, and a class called Event.

The EventDispatcherInterface has methods to add, remove, get, and check for existing listeners. In addition to these, the interface also defines a method to dispatch events, and two methods to add and remove subscribers; see Listing 3. A subscriber is a specialized listener that must implement the EventSubscriberInterface, which we will learn more about later.

Listing 3: Event Dispatcher Interface

<?php namespace Symfony\Component\EventDispatcher; interface EventDispatcherInterface { public function dispatch($eventName, Event $event = null); public function addListener($eventName, $listener, $priority = 0); public function addSubscriber( EventSubscriberInterface $subscriber); public function removeListener($eventName, $listener); public function removeSubscriber( EventSubscriberInterface $subscriber); public function getListeners($eventName = null); public function hasListeners($eventName = null); }



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.